package targetToOffer.sixthDay;

/**
 * @author Godc
 * @description
 */
public class TranslateNum {
    public static void main(String[] args) {
        TranslateNumSolution s = new TranslateNumSolution();
        int i = s.f(12258);
        System.out.println(i);
    }
}
class TranslateNumSolution {
    /**
     * 变相跳台阶的问题，只是每次跳台阶都有一个判断
     * @param num
     * @return
     */
    public int translateNum(int num) {
        if(num<10) return 1;
        int prev = 1,cur = 1,sum = 1;
        String s = String.valueOf(num);
        for (int i = 1; i < s.length(); i++) {
            int val = Integer.valueOf(s.substring(i-1,i+1));
            //val>=10防止出现509这种情况的数字
            if(val>=10&&val<=25) sum = prev+cur;
            else sum = cur;
            prev = cur;
            cur = sum;
        }
        return sum;
    }
    /**
     * 递归做法
     */
    public int f(int num){
        if(num<10) return 1;
        int val = num%100;
        if(val<10||val>25) return f(num/10);
        else return f(num/10)+f(num/100);
    }
}